from django.test import TestCase

# Create your tests here.
import requests
import pymysql
from CategoryConfig import category


# 导入数据
def post_data():
    conn = pymysql.connect(host="192.168.10.106", port=3306,
                           user="root", passwd="root",
                           db="shop_data", charset=u"utf8",
                           cursorclass=pymysql.cursors.DictCursor)

    cur = conn.cursor()
    sql = "SELECT shop_url,goods_id,shop_eid,goods_name,goods_price,cid,first_cid,second_cid,img,description,sell_num,good_count,mid_count,bad_count,appends_count,site_name FROM item LIMIT 104000,150000"
    cur.execute(sql)
    shops = cur.fetchall()
    for shop in shops:
        print(shop)
        a = requests.post("http://127.0.0.1:8000/api/v1/shopitem_tt/", shop)
        print(a.text)
    cur.close()
    conn.close()


# 导入类目字典
def nameclass():
    categorys = category
    for k, v in categorys.items():
        a = requests.post("http://127.0.0.1:8000/api/v1/shopitem_class/", {"class_id": k, "class_name": v})
        print(a.text)


if __name__ == '__main__':
    post_data()
    # nameclass()
